package studentInterface;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Array;
import java.util.Arrays;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class ChangePass extends JFrame implements ActionListener{

	int width;
	int height;
	JButton bntAccept, bntCancel;
	JLabel lblPassowrdOld, lblPasswordNew, lblPasswordNewReType;
	JPasswordField tfPasswordOld, tfPasswordNew, tfPasswordNewReType;
	String username = null;
	char[] password = null;
	private void initialInterface() throws Exception
	{
		UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		Box box, box1, box2, box3, box4, box5;
		setTitle("Đổi mật khẩu");
		width = 500;
		height = 250;
		setSize(width, height);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(HIDE_ON_CLOSE);
		bntAccept = new JButton("Chấp nhận");
		bntCancel = new JButton(" Hủy bỏ ");
		lblPassowrdOld = new JLabel("Mật khẩu cũ");
		lblPasswordNew = new JLabel("Mật khẩu mới");
		lblPasswordNewReType = new JLabel("Đánh lại mật khẩu");
		tfPasswordNew = new JPasswordField();
		tfPasswordNewReType = new JPasswordField();
		tfPasswordOld = new JPasswordField();
		box = Box.createVerticalBox();
		box1 = Box.createHorizontalBox();
		box2 = Box.createHorizontalBox();
		box3 = Box.createHorizontalBox();
		box4 = Box.createHorizontalBox();
		box5 = Box.createHorizontalBox();
		
		
		box1.add(Box.createHorizontalStrut(21));
		box1.add(lblPassowrdOld);
		box1.add(Box.createHorizontalStrut(30));
		box1.add(tfPasswordOld);
		box1.add(Box.createHorizontalStrut(30));
		box2.add(Box.createHorizontalStrut(20));
		box2.add(lblPasswordNew);
		box2.add(Box.createHorizontalStrut(25));
		box2.add(tfPasswordNew);
		box2.add(Box.createHorizontalStrut(30));
		box3.add(Box.createHorizontalStrut(20));
		box3.add(lblPasswordNewReType);
		box3.add(Box.createHorizontalStrut(1));
		box3.add(tfPasswordNewReType);
		box3.add(Box.createHorizontalStrut(30));
		box4.add(Box.createHorizontalStrut(20));
		box4.add(bntAccept);
		box4.add(bntCancel);
		box.add(Box.createVerticalStrut(30));
		box.add(box1);
		box.add(Box.createVerticalStrut(30));
		box.add(box2);
		box.add(Box.createVerticalStrut(30));
		box.add(box3);
		box.add(Box.createVerticalStrut(30));
		box.add(box4);
		
		add(box);
		bntAccept.addActionListener(this);
		bntCancel.addActionListener(this);
	}
	public ChangePass(String username, char[] password) {
		try {
			initialInterface();
			this.username = username;
			this.password = password;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		char[] password = null;
		new ChangePass("", password).setVisible(true);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == bntAccept)
		{
			if(tfPasswordOld.getPassword().length == 0)
			{
				JOptionPane.showMessageDialog(this, "Chưa nhập mật khẩu cũ");
			}
			else if(Arrays.equals(tfPasswordNew.getPassword(), (tfPasswordNewReType.getPassword())) == false)
			{
				JOptionPane.showMessageDialog(this, "Mật khẩu mới không trùng nhau");
			}
			else if(Arrays.equals(tfPasswordNew.getPassword(), (tfPasswordNewReType.getPassword())) == true)
			{
				//Cập nhật lại mật khẩu
			}
		}
		else if(e.getSource() == bntCancel)
		{
			setVisible(false);
		}
	}

}
